#include "boarditem.h"

BoardItem::BoardItem(Board *board, qint32 scene_size, qint8 game_size)
    : QGraphicsItem()
    , m_board(board)
    , m_scene_size(scene_size)
    , m_game_size(game_size)
{
    setPos(scene_item_position());
}

QRectF BoardItem::boundingRect() const
{
    return QRectF(0, 0, item_size(), item_size());
}

const BoardItem::pos_t &BoardItem::game_position() const
{
    return m_game_pos;
}

void BoardItem::set_game_position(const BoardItem::pos_t &pos)
{
    m_game_pos = pos;
    setPos(scene_item_position());
}

qint8 BoardItem::game_size() const
{
    return m_game_size;
}

QPointF BoardItem::scene_item_center() const
{
    qint32 gap_size = item_size() / 2;

    return QPointF(gap_size + scene_item_position().x()
                  , gap_size + scene_item_position().y());
}

QPointF BoardItem::scene_item_position() const
{
    return QPointF(m_game_pos.first * item_size(), m_game_pos.second * item_size());
}

qint32 BoardItem::scene_size() const
{
    return m_scene_size;
}

qint32 BoardItem::item_size() const
{
    return m_scene_size / m_game_size;
}

Board *BoardItem::board()
{
    return m_board;
}

QPointF BoardItem::current_center() const
{
    return QPointF(pos().x() + item_size() / 2, pos().y() + item_size() / 2);
}
